<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<div id="rubrics" class="rubric_dialog" style="display: none; margin-bottom: 10px;">
  <% if @assignment.rubric_association && @assignment.rubric_association.rubric %>
    <%= render :partial => "shared/rubric", :object => @assignment.rubric_association.rubric,
        :locals => {:association => @assignment,
            :rubric_association => @assignment.rubric_association,
            :editable => can_do(@assignment, @current_user, :update),
            :has_assessments => !@assignment.rubric_association.rubric_assessments.empty?, :edit_view => true} %>
  <% end %>
  <div style="display: none;" id="rubric_parameters">
    <input type="hidden" name="rubric_association[association_type]" value="Assignment"/>
    <input type="hidden" name="rubric_association[association_id]" value="<%= @assignment.id %>"/>
    <input type="hidden" name="rubric_association[purpose]" value="grading"/>
  </div>
  <div class="assignment_points_possible" style="display: none;"><%= round_if_whole(@assignment.points_possible) %></div>
  <% if can_do(@assignment, @current_user, :update) %>
    {{> views/shared/rubric_dialog}}
  <% end %>
  {{> views/shared/rubric_criterion_dialog}}
  {{> views/shared/find_outcome}}
  {{> views/shared/rubric}}
  <% if can_do(@assignment, @current_user, :update) %>
    <div style="text-align: center; font-size: 1.2em; margin-top: 10px; display: none;">
      <a href="<%= context_url(@context, :context_rubrics_url) %>" class="add_rubric_link rubric" style="<%= hidden if @assignment.rubric_association %>"><%= t 'links.assign_rubric', "Assign Rubric" %></a>
    </div>
    {{> views/shared/rubric_forms}}
  <% end %>
  <a href="#" class="btn add_rubric_link" style="margin-top: 20px; <%= hidden if @assignment && @assignment.rubric_association %>"><%= image_tag "rubric.png", :alt => '' %> <%= t 'links.add_rubric', "Add Rubric" %></a>
</div>

<script>
  window.ENV = window.ENV || {};
  window.ENV.ROOT_OUTCOME_GROUP = <%= raw @root_outcome_group %>;
  var event = document.createEvent('Event');
  event.initEvent('rubricEditDataReady', true, true);
  document.dispatchEvent(event)
</script>
